package com.frx.sort;

import java.util.Arrays;

/**
 * Created by xurenfeng on 2019/2/18.
 */
public class InsertSort<T extends Comparable<T>> extends Sort<T>{

    public static void main(String[] args){
        InsertSort<Integer> insert = new InsertSort();
        Integer [] a = {3,5,2,4,1};
        System.out.println(Arrays.toString(a));
        insert.sort(a);
        System.out.println(Arrays.toString(a));
    }

    @Override
    public void sort(T[] nums) {
        int N = nums.length;
        for (int i = 1;i < N;i++){
            for (int j = i;j > 0;j--){
                if(less(nums[j],nums[j-1])){
                    swap(nums,j,j-1);
                    System.out.println(Arrays.toString(nums));
                }
            }
        }
    }
}
